package com.base.kotlin.mvvm

import android.arch.lifecycle.ViewModel
import com.base.kotlin.IModel

/**
 * @author zhouzechao
 * ViewModel层，控制M层请求
 */
abstract class BaseViewModel<M : IModel<*>> : ViewModel() {

    var mModel: M? = null

    abstract fun getModel(): M

    fun <T : BaseViewModel<*>> initModel(): T {
        mModel = getModel()
        return this as T
    }

    override fun onCleared() {
        super.onCleared()
        mModel?.destroy()
    }
}